import uSwipeActionItem from "@/components/uni-swipe-action-item/uni-swipe-action-item.vue";
import uniSwipeAction from "@/components/uni-swipe-action/uni-swipe-action.vue";
import comlist from '@/components/comlist/index.vue'	
export default {
	components:{comlist},
	data () {
		return {
			pageNum:1,
			pageSize:100,
			list:[],
			options: [{
				text: '删除',
				style: {
					backgroundColor: '#EE2437' // 删除按钮背景  红的
				}
			}],
			type:1,
			listLabel:[
				{
					name:'方案编号：',
					key:'sn'
				},
				{
					name:'签发时间：',
					key:'modifiedDate'
				},
			],
			listtitle:'干预计划',
			showModal:false,
			showContent:'',
			showModal1:false,
			showContent1:'',
			name: '',
			screenArr:[],
			page:1,
			deleteList: '',
			nullData:false,
			SearchuserId:''
			
		}
	},
	mounted(){
		// this.getlist(1)
		this.getlist(1,{pageIndex:this.page,pageSize:10})
	},
	onReachBottom(){
		if(this.type == 1) {
			if(this.nullData == true){
				return;
			}
			this.page = this.page + 1
			this.getlist(1,{pageIndex:this.page,pageSize:10,userId:this.SearchuserId})
		}else {
			if(this.nullData == true){
				return;
			}
			this.page = this.page + 1
			this.getlist(2,{pageIndex:this.page,pageSize:10,userId:this.SearchuserId,planType:'isPlan'})
		}
		
	},
	methods:{
		nameInput(e){
			const data =  {str:e == 'first'?'':e.detail.value}
			this.$api.selectMembershipList(data).then((res) => {
				if(res.data.returnCode == 200) {
					this.screenArr = res.data.result.list;
				}
			})
		},
		comSearch(e){
			this.page = 1
			this.SearchuserId = e == 'all'? '' : e.userId
			this.nullData = false
			this.name = e == 'all'?'全部': e.realName
			this.deleteList = 1;
			this.screenArr = []
			this.type == 1 ? 
				this.getlist(this.type,{pageIndex:1,pageSize:10,userId:e.userId})
			:
				this.getlist(2,{pageNum:1,pageSize:10,planType:'isPlan',userId:e.userId})
		},
		getlist(e,i){
			e == 1?
				this.$api.InterventionPlanPlanList(i).then((res)=>{
					var data = res.data.result && res.data.result.elements || []			
					if(this.deleteList == 1) {
						this.list = []
						this.list = data
						this.deleteList = ''
					}else {
						this.$set(this,'list',this.list ? this.list.concat(data) : data)
						if(this.list.length >= res.data.result.totalCount){
							this.nullData = true;
						}
					}
				})
			:
				this.$api.InterventionPlanList(i).then((res)=>{
					var data = res.data.result && res.data.result.elements || []
					if(this.deleteList == 1) {
						this.list = []
						this.list = data
						this.deleteList = ''
					}else {
						this.$set(this,'list',this.list ? this.list.concat(data) : data)
						if(this.list.length >= res.data.result.count){
							this.nullData = true;
						}
					}
				})
				
		},
		jump(e){
			e.status == 1 ?
				uni.navigateTo({url:'/pages/quickly/intervenscheme/creat?id='+e.id})
			:
				uni.navigateTo({url:'/pages/quickly/intervenscheme/toView?id='+e.id})
		},
		// inputBlur() {
		// 	this.getlist(1);
		// },
		bindClick(e,n){
			if(!n){
				this.showModal = true
				this.showContent = '是否删除此干预计划方案'
				this.delItem = e
				this.isplan = false
			}else{
				this.showModal = true
				this.showContent = '是否删除此干预计划'
				this.delItem = e
				this.isplan = true
			}
			
			// UserInfodelete
		},
		createPlan() {
			uni.navigateTo({
				url:'/pages/quickly/intervenscheme/creat'
			})
		},
		Modalconfirm(e){
			this.isplan ? 
					this.$api.Interventiondelete(this.delItem.id).then((res)=>{
						if(res.data.returnCode == 200){						
							this.page = 1
							this.deleteList = 1;
							this.nullData = false;
							this.getlist(2,{pageNum:this.pageNum,pageSize:this.pageSize,planType:'isPlan'})
						}
					})
				:
					this.$api.InterventiondeleteByPlan(this.delItem.id).then((res)=>{
						if(res.data.returnCode == 200){
							this.page = 1
							this.deleteList = 1;
							this.nullData = false;
							this.getlist(1,{pageIndex:this.page,pageSize:10})
						}
					})
		},
		carryOut(id) {
			this.showModal1 = true
			this.showContent1 = '是否执行此计划。'
			this.carryId = id;
			
		},
		Modalconfirm1(){
			const _this = this;
			_this.$api.InterventionrunPlan(this.carryId).then((res)=>{
				if (res.data.returnCode == 200) {
					_this.$api.InterventionPlanList({pageNum: 1,pageSize: 20,planType: 'isToday',}).then((res) => {
						if (res.data.returnCode == 200) {
							_this.list = res.data.result && res.data.result.elements || []
						}
					})
				}
			})
		}
	}
}